using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace Company.BLL.DuLieuChuan
{
    public class DonViHaiQuan : BaseClass
    {
        public static DataTable SelectAll()
        {
            string query = "SELECT * FROM t_HaiQuan_DonViHaiQuan ORDER BY Ten";
            DbCommand dbCommand = db.GetSqlStringCommand(query);
            return db.ExecuteDataSet(dbCommand).Tables[0];
        }

        public static string GetName(string id)
        {
            DataSet ds = SelectDynamic(string.Format("ID = '{0}'", id.PadRight(6)), "");
            if (ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["Ten"].ToString();
            }
            return string.Empty;
        }

        public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
        {
            string query = "SELECT * FROM t_HaiQuan_DonViHaiQuan";
            if (whereCondition.Length > 0)
            {
                query = "SELECT * FROM t_HaiQuan_DonViHaiQuan WHERE " + whereCondition;
            }

            if (orderByExpression.Length > 0)
            {
                query += " ORDER BY " + orderByExpression;
            }

            SqlCommand dbCommand = (SqlCommand) db.GetSqlStringCommand(query);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}